//
//  BidJobDetailOfferTableViewCell.swift
//  ezyform
//
//  Created by MoennigQ on 12/12/18.
//  Copyright © 2018 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
class ServiceDetailOfferTableViewCell: TableViewCell {
    var nameLabel: BaseLabel!
    var bidPriceLabel: BaseLabel!
    var dateLabel: BaseLabel!
    var contentLabel: BaseLabel!
    
    override func setUpviews(){
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        //1.
        self.backgroundColor = UIColor.white
        //2.name label
        nameLabel = ContentLabel(R.font.interSemiBold(size: 16))
        nameLabel.textAlignment = .left
        nameLabel.numberOfLines = 0
        self.contentView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.top.left.equalTo(16)
            make.height.width.greaterThanOrEqualTo(0)
        }
        
        //3.price label
        bidPriceLabel = ContentLabel(R.font.interBold(size: 15),hexStr: "#379657")
        //horizonal priority
        bidPriceLabel.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        bidPriceLabel.setContentHuggingPriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.contentView.addSubview(bidPriceLabel)
        bidPriceLabel.snp.makeConstraints { (make) in
            make.top.equalTo(25)
            make.left.equalTo(nameLabel.snp.right).offset(5)
            make.right.equalTo(-16)
            make.height.width.greaterThanOrEqualTo(0)
            
        }
        //4.date label
        dateLabel = ContentLabel(R.font.interRegular(size: 13),hexStr: "#292D32B2")
        self.contentView.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.bottom).offset(2)
            make.left.equalTo(nameLabel)
            make.height.width.greaterThanOrEqualTo(0)
            
        }
        //5.content label
        contentLabel = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D32B2")
        contentLabel.textAlignment = .left
        contentLabel.numberOfLines = 0
        self.contentView.addSubview(contentLabel)
        contentLabel.snp.makeConstraints { (make) in
            make.top.equalTo(dateLabel.snp.bottom).offset(12)
            make.left.equalTo(nameLabel)
            make.right.equalTo(bidPriceLabel)
            make.bottom.equalTo(-16)
        }
        
    }
    func setData(_ model: ServiceDetailOfferModel){
        //去掉小数点，只显示整数部分
        if model.price != 0 {
            let realPrice = Tool().formatFloatStrToCurrency("\(model.price)")
            bidPriceLabel.text = "$\(realPrice)"
        }
        
        nameLabel.text = model.installer_name
        contentLabel.text = model.message
        
        let convertDateStr = DateUtil().getInternalBetweenDate(model.created_at)
        dateLabel.text = convertDateStr
        
    }
}
